Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Conversation

@deeptibaghel
Copy link
Contributor

@deeptibaghel deeptibaghel commented Mar 21, 2018

Fixes #277

  • Added the query to set the sql_mode
  • Added unit test to disallow any other sql_mode

lib/db/mysql.js Outdated

connection.query('SET NAMES utf8mb4 COLLATE utf8mb4_bin;', (err) => {
var mode = REQUIRED_SQL_MODES.join(',')
connection.query('SET SESSION sql_mode = \'' + mode + '\'', function(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use (err) => { here?

lib/db/mysql.js Outdated

connection.query('SET NAMES utf8mb4 COLLATE utf8mb4_bin;', (err) => {
var mode = REQUIRED_SQL_MODES.join(',')
connection.query('SET SESSION sql_mode = \'' + mode + '\'', function(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this use ` ` for the query here? might make it cleaner https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

lib/db/mysql.js Outdated
connection.query('SET SESSION sql_mode = \'' + mode + '\'', function(err) {
if (err) {
return reject(err)
return reject(err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no semicolons in this repo :(

@vladikoff vladikoff requested a review from rfk March 21, 2018 15:53
@deeptibaghel
Copy link
Contributor Author

@rfk made the changes, will squash commits after review :)

lib/db/mysql.js Outdated

var mode = REQUIRED_SQL_MODES.join(',')
connection.query('SET SESSION sql_mode = \'' + mode + '\'', function(err) {
connection.query(`SET SESSION sql_mode = ${mode};`, (err) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might need the ' ' around ${mode} per example in https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

SET SESSION sql_mode = 'modes';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i changed it after this, need to squash commits :(

.then(
assert.fail,
err => {
assert.equal(err.message, `You cannot use any sql mode other than ${mode}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 great to have this test to make sure!

Copy link
Contributor

@rfk rfk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @deeptibaghel, this looks good to me!

We'll need to make an explicit note of this in the deploy doc, and watch out for errors after rolling it out to production. I give it a low-single-digit-percentage chance of uncovering some weird bug when run in production (which is the idea, we just have to be prepared for it).

@deeptibaghel
Copy link
Contributor Author

Thanks @rfk , have squashed the commits :)

@vladikoff vladikoff merged commit c226b07 into mozilla:master Mar 27, 2018
@ghost ghost removed the waffle:active label Mar 27, 2018
@vladikoff
Copy link
Contributor

Thank you @deeptibaghel !!

@deeptibaghel deeptibaghel deleted the sql branch March 27, 2018 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants